package com.o2o.cleaning.month.platform.ebusiness_plat.meituan_tg

import com.alibaba.fastjson.{JSON, JSONObject}
import com.o2o.cleaning.month.platform.ebusiness_plat.meituan_tg.Mttg.{address, mttgAddress}
import com.o2o.utils.Iargs
import org.apache.spark.rdd.RDD
import org.apache.spark.sql.SparkSession

/**
  * @ Auther: o2o-rd-0008
  * @ Date:   2020/6/5 16:23
  * @ Param:  ${PARAM}
  * @ Description: 
  */
object CheckMTTGESData {
  def main(args: Array[String]): Unit = {

    val spark = SparkSession.builder()
      .appName(s"${this.getClass.getSimpleName}")
      .config("spark.debug.maxToStringFields", "2000")
      .config("spark.serializer", "org.apache.spark.serializer.KryoSerializer")
      .config("spark.sql.caseSensitive", "true")
      .config("es.nodes", "192.168.2.247")
      .config("es.port", "9200")
      .config("cluster.name","O2OElastic")
      .config("es.net.http.auth.user", "elastic")
      .config("es.net.http.auth.pass", "changeme")
      .master("local[*]")
      .getOrCreate()

    val sc = spark.sparkContext
    sc.hadoopConfiguration.set("fs.s3a.access.key", Iargs.OBSACCESS)
    sc.hadoopConfiguration.set("fs.s3a.secret.key", Iargs.OBSSECRET)
    sc.hadoopConfiguration.set("fs.s3a.endpoint", Iargs.OBSENDPOINT)
    sc.setLogLevel("WARN")
    var year ="2020"
    var month = "7"
    var platform = "mttg"

    val index7 = "2020_mttg_7/type_1"

    import org.elasticsearch.spark._

    val data5: RDD[String] = sc.esJsonRDD(index7,
      """
        |{
        |  "query": {
        |    "match_phrase": {
        |      "city": "东营市"
        |    }
        |  }
        |}
      """.stripMargin).values


    mttgAddress(spark, spark.read.json(data5).drop(
      "address",
      "administrative_region",
      "aedzId",
      "city",
      "city_grade",
      "city_origin",
      "district",
      "district_origin",
      "economic_division",
      "if_city",
      "if_district",
      "if_state_level_new_areas",
      "latitude",
      "longitude",
      "name",
      "poor_counties",
      "province",
      "regional_ID",
      "registration_institution",
      "rural_demonstration_counties",
      "rural_ecommerce",
      "the_belt_and_road_city",
      "the_belt_and_road_province",
      "the_yangtze_river_economic_zone_city",
      "the_yangtze_river_economic_zone_province",
      "town",
      "urban_agglomerations"), address).toJSON.rdd.map(lines=>{
      val nObject: JSONObject = JSON.parseObject(lines)
      nObject
    }).saveToEs(index7,Map("es.mapping.id" -> "good_id"))

  sc.stop()
}
}
